package com.muyaxuan.mail.controller.customer;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.muyaxuan.mail.dao.GoodsDao;
import com.muyaxuan.mail.dao.GoodsTypeDao;
import com.muyaxuan.mail.dto.Goods;
import com.muyaxuan.mail.dto.GoodsType;
@Controller
@RequestMapping("/customer")
public class ProductController {
	GoodsDao goodsDao = null;
	GoodsTypeDao goodsTypeDao = null;
	@RequestMapping("/proAjax")
	@ResponseBody
	public Goods getGoodsAjax(String code){
		
		goodsDao = new GoodsDao();
		Goods goods = goodsDao.getGoodsByCode(code);
		
		return goods;
	}
	
	/**
	 * 產品列表頁面
	 * @return
	 */
	@RequestMapping("/showProList")
	public String showProList(){
				
		return "product_list";
	}
	/**
	 * 產品詳情頁面
	 * @return
	 */
	@RequestMapping("/showProDetails")
	public String showProDetails(int id,Model data){
		//创建dao
		goodsDao = new GoodsDao();
		//根据id查询商品
		Goods goods = goodsDao.getGoodsById(id);
		//
		String code = goods.getGoodsType().getCode();
		//根据code获取商品小类型
		goodsTypeDao = new GoodsTypeDao();
		List<GoodsType> minTypeList = goodsTypeDao.getMinType(code.substring(0, 4));
		
		//将商品数据放入响应
		data.addAttribute("goods", goods);
		//将该类商品的小类型放入响应
		data.addAttribute("minTypeList",minTypeList);	
		return "product_details";
	}
	
	
	
	
	
	

}
